package cn.alise.controller.apiException;

import java.util.Collections;
import java.util.HashMap;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.RequestMapping;

import cn.alise.controller.common.BaseController;
import cn.alise.qdp.model.apiException.ApiException;
import cn.alise.qdp.model.common.Pagination;
import cn.alise.qdp.service.apiException.ApiExceptionService;

/**
 * 接口系统异常记录控制器
 * Wed Mar 13 20:55:59 CST 2019  CHENH
 */ 
@Controller
@RequestMapping(value = "/apiException")
public class ApiExceptionController extends BaseController {

	private static final long serialVersionUID = 1L;

	@Autowired
	private ApiExceptionService apiExceptionService;

	/**
	 * 获取列表
	 */
	@RequestMapping(value = "/list")
	public String list(HttpServletRequest request, Model model, ApiException args, Pagination page) {

		HashMap<String, Object> params = new HashMap<String, Object>();

		// 查询总行数
		int total = this.apiExceptionService.total(args);
		if (total > 0) {

			page.setTotalCount(total);
			params.put("pageSize",    String.valueOf(page.getRowsPerPage()));
			params.put("currentPage", String.valueOf(page.getCurrentPage()));

			// 设置分页信息
			params.put("start", (page.getCurrentPage() - 1) * page.getRowsPerPage());
			params.put("size",  page.getRowsPerPage());

			//查询条件
			params.put("account",     	args.getAccount());
			params.put("serviceId",     args.getServiceId());
			params.put("serviceName",   args.getServiceName());
			params.put("apiName",     	args.getApiName());
			params.put("startDate",  	args.getStartDate());
			params.put("endDate",  		args.getEndDate());


			List<ApiException> list = this.apiExceptionService.page(params);
			if (!CollectionUtils.isEmpty(list)) {
				model.addAttribute("list", list);
			} else {
				model.addAttribute("list", Collections.EMPTY_LIST);
			}
		}

		model.addAttribute("apiException", args);
		model.addAttribute("pagination", page);

		return "pages/apiException/apiException-list";
	}
}


